package com.transaction.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import java.util.concurrent.Executor;

/**
 * 线程池
 * @author Administrator
 *
 */
@Configuration
public class TaskExecutePool {
	@Autowired
	private Environment env;

    @Bean(name= "thread.pool")
	public Executor taskAsyncPool(){
		ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();  
        executor.setCorePoolSize(Integer.valueOf(env.getProperty("thread.pool.corePoolSize")));
        executor.setMaxPoolSize(Integer.valueOf(env.getProperty("thread.pool.maxPoolSize")));
        executor.setQueueCapacity(Integer.valueOf(env.getProperty("thread.pool.queueCapacity")));
        executor.setThreadNamePrefix("TaskExecutor-");
        executor.initialize();
        return executor;
	}
}
